/*验证demo表单start*/
$(function(){
	jQuery.validator.addMethod('tel',function(value,element){
		var telmatch = /^1[0-9]{10}$/;
		return this.optional(element) || (telmatch.test(value));
	},'请输入正确的手机号码');

	$('#demo').validate({
		errorElement: 'span',
		errorClass: 'false',
		validClass: 'right',
		onfocusout: function(element){
			$(element).valid();
		},
		errorPlacement: function(error,element){
			element.parent().next().append(error);
		},
		highlight: function(element, errorClass, validClass) {
			$(element).removeClass('right').addClass('false');
			$(element).parent().next().removeClass('right').addClass('false').find('i').html('&#xe606;');
		},
		success: function(span){
			span.parent().removeClass('false').addClass('right');
			span.prev('.iconfont').html('&#xe607;');
		},
		rules: {
			username: {
				required: true
			},
			password: {
				required: true,
				minlength: 8,
				maxlength: 16
			},
			password2: {
				required: true,
				equalTo: '#password',
				minlength: 8,
				maxlength: 16
			},
			tel: {
				required: true,
				minlength: 11,
				maxlength: 11,
				digits: true
			},
			sex: {
				required: true
			},
			favorite: {
				required: true,
				minlength: 2
			}
		},
		messages: {
			username: {
				required: '请设置一个用户名'
			},
			password: {
				required: '请设置一个密码',
				minlength: '密码长度不小于8个字符',
				maxlength: '密码长度不大于16个字符'
			},
			password2: {
				required: '请再次确认密码',
				equalTo: '两次输入密码不相同',
				minlength: '密码长度不小于8个字符',
				maxlength: '密码长度不大于16个字符'
			},
			tel: {
				required: '请输入您的常用手机号码',
				minlength: '手机号码长度为11位',
				maxlength: '手机号码长度为11位',
				digits: '手机号码只能输入数字'
			},
			sex: {
				required: '请选择您的性别'
			},
			favorite: {
				required: '请选择您的爱好',
				minlength: '请至少选择两项'
			}
		}
	});
})
/*验证demo表单end*/